import { cloudService } from './index'
import { IBlog, IBlogCategory, IBlogComment, IBlogStats, IBlogVisit, INewBlog } from '@/types/blog'

import { IPageRecord } from '@/types'

export const queryBlogApi = (currentPage: number, pageSize: number): Promise<IPageRecord<IBlog>> =>
  cloudService({
    url: '/blog-service/blog/page',
    method: 'get',
    params: { currentPage, pageSize }
  })

export const queryBlogByIdApi = (id: number): Promise<IBlog> =>
  cloudService({
    url: `/blog-service/blog/content/${id}`,
    method: 'get'
  })

export const queryBlogStatsApi = (): Promise<IBlogStats> =>
  cloudService({
    url: '/blog-service/blog/stats',
    method: 'get'
  })

export const queryLatestBlogApi = (): Promise<IBlog[]> =>
  cloudService({
    url: '/blog-service/blog/latest',
    method: 'get'
  })

export const queryBlogCommentApi = (blogId: number): Promise<IBlogComment[]> =>
  cloudService({
    url: `/blog-service/blog/comment/${blogId}`,
    method: 'get'
  })

export const addBlogCommentApi = (blogComment: IBlogComment): Promise<boolean> =>
  cloudService({
    url: '/blog-service/blog/comment',
    method: 'put',
    data: blogComment
  })

export const queryAdminBlogApi = (currentPage: number,
  pageSize: number): Promise<IPageRecord<IBlog>> =>
  cloudService({
    url: '/admin-service/blog-manage/page',
    method: 'get',
    params: { currentPage, pageSize }
  })

export const queryAdminBlogByIdApi = (id: number): Promise<IBlog> =>
  cloudService({
    url: `/admin-service/blog-manage/content/${id}`,
    method: 'get'
  })

export const queryAdminBlogCategoryApi = (): Promise<IBlogCategory[]> =>
  cloudService({
    url: '/admin-service/blog-manage/category',
    method: 'get'
  })

export const addBlogApi = (blog: INewBlog): Promise<boolean> =>
  cloudService({
    url: '/admin-service/blog-manage',
    method: 'post',
    data: blog
  })

export const updateBlogApi = (id: number, blog: INewBlog): Promise<boolean> =>
  cloudService({
    url: `/admin-service/blog-manage/${id}`,
    method: 'put',
    data: blog
  })

export const deleteBlogApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/admin-service/blog-manage/${id}`,
    method: 'DELETE'
  })

export const queryBlogVisitApi = (currentPage: number,
  pageSize: number): Promise<IPageRecord<IBlogVisit>> =>
  cloudService({
    url: '/admin-service/blog-manage/visit',
    method: 'get',
    params: { currentPage, pageSize }
  })
